<?php
class Gallery_Form_AlbumAdd extends Promotor_Form_Scaffold {
	public function init() {
		$this->setMethod('post');

		$this->setDecorators(array(
			'FormElements',
            array('TabContainer', array(
                'id' => 'tabContainer',
                'style' => 'width: 100%; height: 500px;',
                'dijitParams' => array(
                    'tabPosition' => 'left'
                ),
            )),
            'Dojo_ValidateOnSubmit',
            'DijitForm',
        ))
        ->addPrefixPath('Promotor_Form_Decorator_','Promotor/Form/Decorator', self::DECORATOR);
        
       $this->addElement('SubmitButton','action', array('ignore' => true,'label'=>'Dodaj'));

		$subForm = $this->_getContentForm();
        $this->addSubForm($subForm, 'contenttab');
        
        $subForm = $this->_getCategoryForm();
        $this->addSubForm($subForm, 'categorytab');
        
        $subForm = $this->_getCalendarForm();
        $this->addSubForm($subForm, 'calendartab');
        
        $subForm = $this->_getSeoForm();
        $this->addSubForm($subForm, 'seotab');
        
        $subForm = $this->_getExForm();
        $this->addSubForm($subForm, 'exttab');
	}
	

	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getContentForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'contenttab',
            'legend' => 'Treść',
        ));
        $subForm
        	->addElement(
                'ValidationTextBox',
                'name',
                array(
                    'label' => 'Nazwa albumu',
                    'required'  => true,
                )
            )
            ->addElement(new KontorX_Form_Element_Db_Select('gallery_id', array(
            	'label' => 'Galeria',
                'description' => 'Wybierz galerię, do której będzie należeć album',
            	'required' => true,
            	'tableName' => 'gallery',
            	'tableCols' => array('key' => 'id','value' => 'name')
            )));

		$content = new Zend_Form_Element_Textarea('description', array(
			'label'        => 'Opis albumu',
			'inheritWidth' => 'true',
            'required' 	   => false
		));
		$content->addDecorator(new KontorX_Form_Decorator_TinyMCE());
		$subForm->addElement($content);

        return $subForm;
    }

	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getCategoryForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'categorytab',
            'legend' => 'Kategoria',
        ));
        $tree = new KontorX_Form_Element_JsTree('tree', array(
			'label'        => 'Kategoria',
            'required' 	   => false,
        	'registerInArrayValidator' => false,

        	'jsOptions' => array(
        		'data' => array(
        			'url' => 'site/site/list/format/jsTree',
        			'async' => false
        		)
        	)
		));
		$subForm->addElement($tree);
		
        return $subForm;
    }
    
	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getCalendarForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'calendartab',
            'legend' => 'Kalendarz',
        ));
        $subForm->addElement(
                'DateTextBox',
                'time_create',
                array(
                    'label' => 'Data utworzenia',
                	'value'  => date('Y-m-d'),
                	'datePattern' => 'yyyy-MM-dd',
                    'required'  => true
                )
            );

        return $subForm;
    }
    
    /**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getSeoForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'metatab',
            'legend' => 'Pozycjonowanie'
        ));
        $subForm
        	->addElement(
                'ValidationTextBox',
                'alias',
                array(
                    'label' => 'Alias galerii',
                    'required'  => false,
                    'regExp' => '[\w\d\-\s]+',
                    'invalidMessage' => 'Tylko tekst bez polskich znaków diakrytycznych!',
                	'filters' => array(
                		'strtolower' => new Zend_Filter_StringToLower(),
                		'rewrite' => new KontorX_Filter_Word_Rewrite()
                	),
                	'validators' => array(
                		'db_no_exsists' => new Zend_Validate_Db_NoRecordExists('gallery_album','alias')
                	)
                )
            )
            ->addElement(
                'Textarea',
                'meta_keywords',
                array(
                    'label'      => 'Słowa kluczowe',
                    'trim'       => true
				)
            )
            ->addElement(
                'Textarea',
                'meta_description',
                array(
                    'label'      => 'Opis strony',
                    'trim'       => true
                )
            );
            
        return $subForm;
    }
    
	/**
     * @return Zend_Dojo_Form_SubForm
     */
    protected function _getExForm() {
    	$subForm = new Zend_Dojo_Form_SubForm();
        $subForm->setAttribs(array(
            'name'   => 'exttab',
            'legend' => 'Zaawansowane'
        ));
        $subForm
            ->addElement(
            	'CheckBox',
            	'publicated',
            	array(
            		'label' => 'Publikować',
            		'value' => 'on',
            		'checked' => true
            	)
            )->addElement(
                'select',
                'display_type',
                array(
                	'label' => 'Szablon strony',
                	'multiOptions' => array(
                		'DEFAULT' => 'Podstawowy (xhtml)',
		                'AUTOVIEWER' => 'Przeglądanie po jednej fotografii (flash)',
		                'SIMPLEVIEWER' => 'Proste przeglądanie (flash)',
		                'TILTVIEWER' => 'Galeria 3D (flash)',
                		'POSTCARDVIEWER' => 'Pocztówki (flash)',
                	)
                )
            );
            
        return $subForm;
    }
}